{% extends 'admin_base.html' %}

{% block title2 %}
    管理博文
{% end %}

{% block admin_content %}
<div class="entry-box manage-articles">
    <h4><strong>管理博文</strong></h4>
    <hr/>
    <p><span class="glyphicon glyphicon-file"></span>博文总数：<span class="badge">{{ pager.totalCount }}</span></p>
    <div class="row articles-list">
        <div class="list-handle">
            <form class="manage-articles" method="GET" action="">
                <div class="form-group">
                    <div class="col-sm-2">
                        <select class="form-control" id="types_choice" name="articleType_id" >
                            <option value="">全部分类</option>
                            {% for at in article_types %}
                            <option value="{{at.id}}"
                                    {%if article_search_params and str(article_search_params.articleType_id)==str(at.id) %}
                                    selected
                                    {%end%} >{{at.name}}</option>
                            {% end %}
                        </select>
                    </div>
                    <div class="col-sm-2">
                        <select class="form-control" id="source_choice" name="source_id" >
                            <option value="">全部来源</option>
                            {% for source in SiteCollection.article_sources %}
                            <option value="{{source.id}}"
                                    {% if article_search_params and str(article_search_params.source_id)==str(source.id) %}
                                    selected
                                    {%end%} >{{source.name}}</option>
                            {% end %}
                        </select>
                    </div>
                    <div class="col-sm-2">
                        <button type="submit" class="btn btn-primary">
                            <span class="glyphicon glyphicon-search"></span> 筛选
                        </button>
                    </div>
                </div>
            </form>
        </div>
        <div class="list-detials">
            <table class="table table-striped table-hover">
                <thead>
                <tr class="table-header">
                    <th class="table-checkbox-or-left"><input type="checkbox" id="select-all">全选</th>
                    <th>博文标题</th>
                    <th>来源</th>
                    <th>分类</th>
                    <th>发表日期</th>
                    <th>编辑</th>
                    <th>删除</th>
                </tr>
                </thead>
                <tbody>
                    {% for article in pager.result %}
                    <tr>
                        <td class="table-checkbox-or-left"><input type="checkbox" class="op_check" value="{{ article.id }}"></td>
                        <td class="table-checkbox-or-left"><a href="{{ reverse_url('article', article.id) }}" target="_blank">{{ article.title }}</a></td>
                        <td>
                            <a href="{{ reverse_url('articleSource', article.source.id) }}" target="_blank">
                                {{ article.source.name }}
                            </a>
                        </td>
                        <td>
                            <a href="{{ reverse_url('articleType', article.articleType.id) }}" target="_blank">
                                {{ article.articleType.name }}
                            </a>
                        </td>
                        <td>{{ article.create_time.strftime("%Y-%m-%d %H:%M:%S") }}</td>
                        <td>
                            <a href="{{ reverse_url('admin.article', article.id) }}">
                                <span class="glyphicon glyphicon-pencil" title="编辑博文"></span>
                            </a>
                        </td>
                        <td>
                            <a class="btn btn-sm btn-default"
                               onclick="delCfm('{{reverse_url('admin.article.update', article.id, 'delete')}}')"
                               title="删除博文">
                                <span class="glyphicon glyphicon-trash delete-article"></span>
                            </a>
                        </td>
                    </tr>
                    {% end %}
                </tbody>
            </table>
        </div>
        {% module Template("_macros.html", pager=pager, url=reverse_url('admin.articles'), params=article_search_params.to_url_params()) %}
    </div>
</div>
<!-- 信息删除确认: For delete an article confirm -->
<div class="modal fade" id="delCfmModel">
    <div class="modal-dialog">
        <div class="modal-content message_align">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>
                <h4 class="modal-title">确认删除博文？</h4>
            </div>
            <div class="modal-body">
                <p>将连同博文评论一起删除，并且删除后不可恢复，您确认要删除吗？</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button id="cfmClick" class="btn btn-success" data-dismiss="modal">确定</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% end %}